#include "Bootstrap.h"
#include "version.h"

#include <QtCore/QTranslator>
#include <QtGui/QIcon>
#include <QFont>
#include <QStyleFactory>

#include "utils/Logger.h"

#define TAG "Bootstrap.cpp"

Bootstrap::Bootstrap(QApplication *app, QObject *parent) : QObject(parent)
{
    //...load language
    //.................
    // you need using 'lupdate xxx.pro' to update your *.ts file first,
    // then using 'lrelease xxx.pro' to release your *.ts file to *.qm file
    //
    // you can load 'lang' from settings, if you need dynamic translation
    QString lang = "zh_rCN";
    QTranslator *trans = new QTranslator(this);
    //...load custom translation
    trans->load(QString(":/i18n/app_%1.qm").arg(lang));
    app->installTranslator(trans);
    //... set value for QSettings
    app->setOrganizationName("Geekor");
    app->setOrganizationDomain("itone.wang");
    app->setApplicationName(QObject::tr("ComToolOne"));

    //... set other info
    app->setApplicationVersion(APP_VERSION_NAME);
    app->setApplicationDisplayName(QObject::tr("ComToolOne"));
    app->setWindowIcon(QIcon(":/ico/logo"));

    //... set default font
    QFont font = app->font();
#if defined(Q_OS_MAC)
    font.setPixelSize(10);
#elif defined(Q_OS_LINUX)
    font.setPixelSize(11);
#endif
    app->setFont(font);

    //... set ui style
#if 1
    //qDebug() << QStyleFactory::keys(); //("Windows", "Fusion")
    QApplication::setStyle(QStyleFactory::create("Fusion"));
#endif

    //... enable log system
    Logger::enable();
}

void Bootstrap::start()
{
    //....................... start services .........
    //TODO: you can add some startup things here
}
